const app = getApp();
Page({

  data: {
    applyList:[],
    applyId: null,
    guideModal: false,
    guideText: ''
  },
  onShow() {
    let that = this;
    wx.request({
        url: app.rootUrl + '/getTeacherApplys',
        data: {userId: app.accountInfo().accountId},
        header: {
          'Content-Type': 'application/x-www-form-urlencoded',
        },
        method: 'POST',
        success: function (res) {
          that.setData({
            applyList: res.data.rows
          });
        }
      })
  },
  guideTextInput: function(e) {  
    this.setData({  
        guideText: e.detail.value 
    });  
  },
  openGuide(e){
    let that = this
    const id= e.currentTarget.dataset['id'];
    that.setData({
        applyId: id,
        guideModal: true
    });
  },
  closeGuide(){
    let that = this
    this.setData({  
        guideModal: false  ,
        guideText: ''
      }); 
  },
  applyGuide(){
      let that = this
      if(!that.data.guideText){
        wx.showToast({title: '请输入',
        icon: 'none',})
        return null
      }
        wx.request({
            url: app.rootUrl + '/applyGuide',
            data: {applyId: that.data.applyId, applyGuide: that.data.guideText},
            header: {
            'Content-Type': 'application/x-www-form-urlencoded',
            },
            method: 'POST',
            success: function (res) {
                wx.showToast({
                    title: res.data.msg,
                    icon: 'none',
                  })
                  if(res.data.status === 0){
                      that.onShow()
                      that.closeGuide()
                  }
            }
        })
  }
})